<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-12-20
 * Time: 11:42
 */

namespace app\common\model;

use think\Model as ThinkModel;

//银行列表模型
class Message extends ThinkModel
{
    protected $name = 'qt_message';
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;


    public  function  getlist($user_id,$page,$limit,$status){
        $where=[];
        if($status != '2'){
            $where[]=['type','eq',$status];
        }
        $type=[
            '1'=>'系统消息' ,
            '2'=> '呼叫服务消息' ,
            '3' =>'商品下单' ,
            '4'=> '技师下钟消息' ,
            '5'=> '加钟消息' ,
            '6'=> '技师提前下班消息' ,
            '7'=> '技师上班迟到消息' ,
            '8' =>'会员消费警告' ,
        ];
        $list=$this->where($where)
            ->page($page,$limit)
            ->where('to_user_id',$user_id)
            ->select()
            ->each(function ($item)use($type){
               $item['type_name']=$type[$item['type']];
               $item['created_time']=ST($item['created_time']);
                $item['read_name']=$item['read']=='0'?'未读':'已读';
               return $item;
            });
        return $list;

    }


    public  function  message_info($user_id,$id){
        $list=$this
            ->where('to_user_id',$user_id)
            ->where('id',$id)
            ->find();
        $list['created_time']=ST($list['created_time']);
        //改为已读
        $this->where('id',$id)->update(['read'=>'1']);
        return $list;

    }
}